//二叉树的遍历
//先序遍历 //递归实现
function preorderTravelNode(node){
    if(!node){return false}
    console.log(node.value);
    preorderTravelNode(node.left)
    preorderTravelNode(node.right)
}
// 先序遍历  非递归实现
function preorderTravelNodeNotDg(node){
    const stack = []
    if(!node){return false}
    stack.push(node)
    while(stack !== 0){
        const root = stack.pop()
        console.log(node.value)
        if(root.right){
            stack.push(node.right)
        }
        if(root.left){
            stack.push(node.left)
        }
    }
}
//中序遍历 递归实现
function midorderTravelNode(node){
    midorderTravelNode(node.left)
    console.log(node.value);
    midorderTravelNode(node.right)
}
// 中序遍历  非递归实现
function preorderTravelNodeNotDg(node){
    const stack = []
    const root = node
    while(stack.length !== 0 || root){
        if(root){
            stack.push(root)
            root = root.left
         }else{
            root = stack.pop()
            console.log(root)
            root = root.right
         }
    }
    
}

// 后续遍历